import lejos.nxt.Button;
import lejos.nxt.LightSensor;
import lejos.nxt.MotorPort;
import lejos.nxt.SensorPort;

public class Vehicle2bThreads {
	LightSensor l1 = new LightSensor(SensorPort.S3);
	LightSensor l2 = new LightSensor(SensorPort.S4);
	
	public static void main(String[] args) {
		new Vehicle2bThreads();
	}
	public Vehicle2bThreads(){
		ThreadControl left = new ThreadControl(MotorPort.C, l1, 60);
		ThreadControl right = new ThreadControl(MotorPort.B, l2, 60);
		
		left.start();
		right.start();
	}
	
	private class ThreadControl extends Thread{
		private MotorPort m;
		private LightSensor s;
		private int defSpeed;
		
		public ThreadControl(MotorPort motor, LightSensor sensor, int defaultSpeed){
			m = motor;
			s = sensor;
			defSpeed = defaultSpeed;
		}
		
		@Override
		public void run() {
			while(!Button.ESCAPE.isPressed()){
				m.controlMotor(defSpeed + (s.readNormalizedValue()-500)/4, 1);
			}
		}
	}
}